import Vue from "vue";
import Router from "vue-router";
// import worktable from '@/router/modules/worktable'

import pointmanage from "@/router/modules/pointmanage";
import workarea from "@/router/modules/workarea";
import paymanage from "@/router/modules/paymanage";
const maindata = [pointmanage, workarea, paymanage];
import cartypemanage from "@/router/modules/cartypemanage";
import carlist from "@/router/modules/carlist";
import carback from "@/router/modules/carback";
const car = [cartypemanage, carlist, carback];
import postmanmanage from "@/router/modules/postmanmanage";
import driver from "@/router/modules/driver";
import scheduling from "@/router/modules/scheduling";
const people = [postmanmanage, driver, scheduling];
import ordermanage from "@/router/modules/ordermanage";
import sendlistmanage from "@/router/modules/sendlistmanage";
const work = [ordermanage, sendlistmanage];
import sendtask from "@/router/modules/sendtask";
import line from "@/router/modules/line";
import get from "@/router/modules/get";
import outsend from "@/router/modules/outsend";
const diaodutai = [sendtask, line, get, outsend];
Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: {
          title: "工作台",
          icon: "worktable",
        },
      },
      {
        path: "datamanage",
        name: "Datamanage",
        component: () => import("@/views/datamanage"),
        meta: { title: "基础数据管理", icon: "jichu" },
        children: maindata,
      },
      {
        path: "car",
        name: "Car",
        component: () => import("@/views/car"),
        meta: { title: "车辆管理", icon: "car" },
        children: car,
      },
      {
        path: "people",
        name: "People",
        component: () => import("@/views/people"),
        meta: { title: "员工管理", icon: "man" },
        children: people,
      },
      {
        path: "business",
        name: "Business",
        component: () => import("@/views/business"),
        meta: { title: "业务管理", icon: "yewu" },
        children: work,
      },
      {
        path: "diaodu",
        name: "Diaodu",
        component: () => import("@/views/diaodu"),
        meta: { title: "调度管理", icon: "diaodu" },
        children: diaodutai,
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
